﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Criterion;
using SuperMarketManagement.Entity;

namespace SuperMarketManagement.DAO.NHibernate
{
    public class CategoryDAO : GenericDAO<Category, long>
    {
        public CategoryDAO(ISession session)
            : base(session)
        {
        }

        public Category GetRoot()
        {
            return
                Session.CreateCriteria(typeof(Category))
                .Add(Expression.Eq("Name", "root"))
                .Add(Expression.IsNull("Parent")).UniqueResult<Category>();
        }
    }
}
